package com.netbao.sys.utils;



import com.netbao.excetion.RRException;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;

/**
 * @author zhouxp
 * @create 2019-08-24 16:33
 */
public class ValidatorUtil {
	private  static Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

	public static void validatorEntity(Object entity,Class<?> ...group){
		Set<ConstraintViolation<Object>> validates = validator.validate(entity, group);

		if(!validates.isEmpty()){
			String message = validates.iterator().next().getMessage();
			throw  new RRException(message);
		}

	}
}
